package com.jiepos.mpos.biz.service.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.service.service.CustomProfitService;
import com.jiepos.mpos.biz.user.service.AppInsInfService;
import com.jiepos.mpos.common.entity.App_Custom_ProfitEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;

/**
 * @author Zhao.Jinkui
 * @version 1.0
 * @ProjectName: mpos
 * @Package com.jiepos.mpos.biz.service.controller
 * @ClassName CustomProfitController
 * @history
 * @UpdateRemark []
 * @since 2017/10/8
 */
@Controller
@RequestMapping("customProfit")
public class CustomProfitController extends BaseController {

    @Autowired
    private CustomProfitService customProfitService;

    @Autowired
    private AppInsInfService appInsInfService;

    /**
     * 进入会员分润设置列表页面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getCustomProfitList.do")
    public ModelAndView getCustomProfitList(HttpServletRequest request, HttpServletResponse response, Pagination pagination){
        ModelAndView model = new ModelAndView("/module/service/customprofit/customprofit_list");
        return super.getDetail(request, response, model);
    }

    /**
     * 查询会员分润Json数据
     * @param pagination
     * @param appCustomProfitEntity
     * @return
     */
    @RequestMapping("/getCustomProfitListJson.do")
    public @ResponseBody
    Map getCustomProfitListJson(HttpServletRequest request, Pagination pagination, App_Custom_ProfitEntity appCustomProfitEntity){
        return customProfitService.findByCondition(request, pagination,appCustomProfitEntity);
    }

    /**
     * 根据uuid加载会员分润设置详情页面
     * @param request
     * @param response
     * @param custom_profit_uuid
     * @return
     */
    @RequestMapping("/getCustomProfitDetail.do")
    public ModelAndView getCustomProfitDetail(HttpServletRequest request, HttpServletResponse response,String custom_profit_uuid){
        ModelAndView model = new ModelAndView("/module/service/customprofit/customprofit_detail");
        App_Custom_ProfitEntity entity = customProfitService.findByUUID(custom_profit_uuid);
        model.addObject("customProfitEntity",entity);
        //根据机构uuid得到机构信息
        Map appInsInfEntity=appInsInfService.getInsInfById(request,entity.getIns_uuid());
        model.addObject("ins_name",appInsInfEntity.get("INS_CD")+"-"+appInsInfEntity.get("INS_CN_NM"));
        return super.getDetail(request,response,model);
    }
    
    /**
     * 根据uuid加载会员分润设置详情页面
     * @param request
     * @param response
     * @param custom_profit_uuid
     * @return
     */
    @RequestMapping("/getCustomProfitDetailShow.do")
    public ModelAndView getCustomProfitDetailShow(HttpServletRequest request, HttpServletResponse response,String custom_profit_uuid){
        ModelAndView model = new ModelAndView("/module/service/customprofit/customprofit_detail_show");
        App_Custom_ProfitEntity entity = customProfitService.findByUUID(custom_profit_uuid);
        model.addObject("customProfitEntity",entity);
        //根据机构uuid得到机构信息
        Map appInsInfEntity=appInsInfService.getInsInfById(request,entity.getIns_uuid());
        model.addObject("ins_name",appInsInfEntity.get("INS_CD")+"-"+appInsInfEntity.get("INS_CN_NM"));
        return super.getDetail(request,response,model);
    }
    

    /**
     * 进入新增会员分润设置界面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/getCustomProfitAdd.do")
    public ModelAndView getCustomProfitAdd(HttpServletRequest request, HttpServletResponse response){
        ModelAndView model = new ModelAndView("/module/service/customprofit/customprofit_detail");
        return super.getDetail(request, response, model);
    }

    /**
     * 保存会员分润设置信息
     * @param request
     * @param response
     * @param entity
     * @return
     */
    @RequestMapping("/saveCustomProfit.do")
    @ResponseBody
    public String saveCustomProfit(HttpServletRequest request,HttpServletResponse response,App_Custom_ProfitEntity entity){
        String isSuccess = customProfitService.saveCustomProfit(entity,super.getLoginUser(request, response));
        return isSuccess;
    }


    /**
     * 检查机构是否已进行过相同的会员分润设置
     * @param entity
     * @return 不存在返回success，存在返回error
     */
    @RequestMapping("checkInsProfitStatus.do")
    public @ResponseBody String checkInsProfitStatus(App_Custom_ProfitEntity entity){
        return customProfitService.checkInsProfitStatus(entity);
    }
    

    /**
     * 删除会员分润设置信息
     * @param request
     * @param response
     * @param entity
     * @return
     */
    @RequestMapping("/deleteCustomProfit.do")
    public ModelAndView deleteCustomProfit(HttpServletRequest request,HttpServletResponse response, String ids){
        customProfitService.deleteCustomProfit(request, ids);
        return new ModelAndView(new RedirectView("getCustomProfitList.do"), super.getLoginUser(request, response));
    }
    
    

}
